/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.edu.fatec.ads.bo;

import br.edu.fatec.ads.classes.Andar;
import br.edu.fatec.ads.classes.Sala;
import br.edu.fatec.ads.dao.HibernateGenericDAO;
import br.edu.fatec.ads.util.ComboBoxItem;
import br.edu.fatec.ads.util.CriteriosUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.HibernateException;
import org.hibernate.criterion.Criterion;

/**
 *
 * @author Ubirajara
 */
public class BusinessObjectSala implements IBusinessObject{

    private HibernateGenericDAO dao = null;

    public BusinessObjectSala(){
        dao = new HibernateGenericDAO(Sala.class);
    }

    public void beginTransaction() {
        dao.beginTransaction();
    }

    public void commitTransaction() {
        dao.commitTransaction();
    }

    public void rollbackTransaction() {
        dao.rollbackTransaction();
    }

    public void clearSession() {
        dao.clearSession();
    }

    public List<ComboBoxItem> recuperarComboSalas(Andar andarSelecionado){
        List<ComboBoxItem> comboSalas = new ArrayList<ComboBoxItem>();
        List<Sala> salasEncontradas = null;
        Map<String, Object> criterios = new HashMap<String, Object>();
        Map<String, Object> camposBusca = new HashMap<String, Object>();
        List<Criterion> criterions = null;

        camposBusca.put("andar", andarSelecionado);
        criterios.put(CriteriosUtil.CRITERIOS_OBJETO, camposBusca);

        criterions = CriteriosUtil.getInstance().montaCriterios(criterios);

        try{
            salasEncontradas = dao.findByCriterion(criterions);
        }catch(HibernateException cause){
            cause.printStackTrace();
        }

        if(salasEncontradas != null && !salasEncontradas.isEmpty()){
            for (Sala sala : salasEncontradas) {
                comboSalas.add(new ComboBoxItem(sala.getCodigo(), sala.getNome()));
            }
        }

        return comboSalas;
    }

}
